#include "thread.hpp"

int ticket = 10000;

void *handler(void *arvg)
{
    // 现在我来模拟一下抢票，有10000张票
    while( ticket > 0)
    {
        usleep(1034);  // 直接休息一毫秒，看现象
        std::cout << (char *)arvg << "购票成功 : " << ticket << std::endl;
        ticket--;
    }

}



int main()
{
    // 创建线程出来
    std::unique_ptr<Threads> thread1(new Threads("user1", 1, handler,(void*)"user1"));
    std::unique_ptr<Threads> thread2(new Threads( "user2", 2,handler,(void*)"user2"));
    std::unique_ptr<Threads> thread3(new Threads( "user3", 3,handler,(void*)"user3"));
    std::unique_ptr<Threads> thread4(new Threads( "user4", 4,handler,(void*)"user4"));

  

    thread1->join();
    thread2->join();
    thread3->join();
    thread4->join();
    return 0;
}